<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--采购计划变更-->
<div class="modal fade" id="modal-edit">
    <div class="modal-dialog" style="width:1200px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">采购计划变更</h4>
            </div>
            <div class="modal-body">
                <table id="report-plan-table"></table>
                <hr>
                <form id="editForm" class="form-horizontal">
                    <input type="hidden" name="sppId">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">物料描述</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="sppMatDesc" placeholder="物料描述">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">数量</label>
                                    <div class="col-sm-8">
                                        <input type="number" step="0.1" class="form-control" name="sppNum" autocomplete="off" placeholder="数量">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">跟踪号</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="sppTrackCode" placeholder="供应商">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">SAP物料编码</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="sppSapCode" placeholder="SAP物料编码">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">品牌</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="sppBrand" autocomplete="off" placeholder="品牌">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">备注计划用途</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="sppProjectName" autocomplete="off" placeholder="备注计划用途">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">变更原因</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="spcReason" autocomplete="off" placeholder="变更原因">
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">是否删除</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="spcDel" autocomplete="off" placeholder="">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="buy:buychange:edit" type="button" class="btn btn-info" id="btn-edit">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header"><h1>采购计划变更</h1></section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="text" name="sppMatDesc" class="form-control" placeholder="请输入物料描述">
                                </div>
                                <div class="form-group">
                                    <label>SAP物料编码</label>
                                    <input type="text" name="sppSapCode" class="form-control" placeholder="请输入SAP物料编码">
                                </div>

                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="sppProjectCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="sppProjectName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>计划员</label>
                                    <input type="text" name="sppPlanner" class="form-control" placeholder="">
                                </div>
                                <div class="form-group">
                                    <label>提报计划变更</label>
                                    <select name="rppChangeMark" class="form-control">
                                        <option value="1" selected="selected">有变更</option>
                                        <option value="0">无变更</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    var table, reportTable;

    function change(row) {
        $("#editForm").fillData(row);
        if (row.sppIntegraFlag) {
            js.post({
                url:ctx + 'buy/buyPlanChange/status',
                data:{
                    sppId: row.sppId
                },
                success: function(res) {
                    if (res) {
                        $("#editForm input[name=sppMatDesc]").attr('readonly', true);
                    } else {
                        $("#editForm input[name=sppMatDesc]").attr('readonly', false);
                    }
                }
            });
        } else {
            $("#editForm input[name=sppMatDesc]").attr('readonly', false);
        }
        js.table.jump(reportTable, ctx + "buy/buyPlanChange/list/" + row.sppId);
        js.modal.open("modal-edit");
    }

    $(function () {
        $("title").html($("title").html()+" —— 采购计划变更");
        /** 加载表格 */
        table = js.table.init({
            url: ctx + "buy/buyPlanChange/list",
            showColumns: false,
            showExport: false,
            columns: [
                {
                    title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                // { title: "变更状态", field: 'sppChangeStatus'},
                // { title: "采购状态", field: 'sppStatus'},
                { title: "项目编号", field: 'sppProjectCode'},
                { title: "项目名称", field: 'sppProjectName'},
                { title: "联系人", field: 'sppDesigner'},
                { title: "跟踪号", field: 'sppTrackCode'},
                { title: "采购物料描述", field: 'sppMatDesc'},
                { title: "SAP物料编码", field: 'sppSapCode'},
                { title: "采购数量", field: 'sppNum'},
                // { title: "供应商", field: 'sppSupplier'},
                // { title: "品牌", field: 'sppBrand'},
                {
                    title: "操作",
                    field: 'sppId',
                    width: '60px',
                    formatter: function (value, row) {
                        var actions = [];
                        if (hasP("buy:buychange:edit")) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="change(' + js.jsonStringify(row) + ')"> 变更</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /** 提报计划变更信息表 */
        reportTable = js.table.init({
            id: 'report-plan-table',
            url: ctx + "buy/buyPlanChange/list/1",
            pagination: false,
            firstLoad: false,
            showColumns: false,
            queryForm: null,
            showExport: false,
            columns: [
                { title: "提报项目编号", field: 'rpcProjectCode'},
                { title: "提报项目名称", field: 'rpcProjectName'},
                { title: "提报物料描述", field: 'rpcMatDesc'},
                { title: "提报数量单位", field: 'rpcNum'},
                { title: "更改后物料描述", field: 'rpcNewMatDesc'},
                { title: "更改后数量单位", field: 'rpcNewNum'},
                { title: "更改后品牌", field: 'rpcNewBrand'},
                { title: "更改后备注", field: 'rpcNewRemark'}
            ]
        });

        /** editReportPlanForm 表单验证规则 */
        js.validate.init("editForm", {
            fields: {
                sppMatDesc: {validators: {notEmpty: {message: '请输入SAP物料描述'}}},
                sppNum: {validators: {notEmpty: {message: '请输入数量'}}},
                // sppTrackCode: {validators: {notEmpty: {message: '请输入跟踪号'}}},
            }
        });
        /** 计划变更 */
        $("#btn-edit").click(function () {
            js.validSubmit({
                formId: "editForm",
                url: ctx + "buy/buyPlanChange/change",
                data: new FormData($("#editForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-edit");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        /** 变更计划模态框隐藏事件， 重置表单，重置验证 */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("editForm");
            js.reset("editForm");
        });



    });

</script>
</body>
</html>
